<?php

class Model
{

    private $path;
    private $models = array();

    function __construct($path = null) {
        if ($path != null && file_exists($path) && is_dir($path)) {
            $this->path = $path;
        }
    }
    
    function SetPath($path) {
        if (file_exists($path) && is_dir($path)) {
            $this->path = $path;
        }
    }
    
    function GetPath() {
        return $this->path;
    }

    function __get($name) {
        if (in_array($name, $this->models)) {
            return $this->models[$name];
        }
        require_once $this->path . DS . 'm_' . $name . '.php';
        $modelName = 'Model_' . $name;
        $mHandle = new $modelName();
        $this->models[$name] = $mHandle;
        return $mHandle;
    }
}